
import { ListenID } from "../../ListenID";
import NetAdapter from "../../adpapter/NetAdapter";
import { AlertManager, AlertType } from "../../alert/AlertManager";
import { MVC } from "../../framework/MVC";
import { Notifier } from "../../framework/Notifier";
import { Manager } from "../../manager/Manager";

const { ccclass, property } = cc._decorator;

@ccclass
export default class TixianRenzhengView extends MVC.BaseView {

    protected changeListener(enable: boolean): void {
        // throw new Error("Method not implemented.");
    }

    @property(cc.EditBox)
    zfbaccount: cc.EditBox = null;

    @property(cc.EditBox)
    realname: cc.EditBox = null;

    private tixiancoin: number = 0;

    // onLoad () {}

    /*
     * 打开界面回调，每次打开只调用一次
     */
    public onOpen(args: any): void {
        super.onOpen(args);
        this.tixiancoin = Number(args);
    }

    start() {

    }

    /*
     * 关闭界面回调，每次打开只调用一次
     */
    public onClose(): void {
        Manager.audio.playAudio(501);
        super.onClose();
    }

    public onClickTiXian() {
        let param = {
            money: this.tixiancoin,
            identity: this.zfbaccount.string,
            name: this.realname.string,
        }

        AlertManager.showAlert(AlertType.SELECT, {
            reasonDesc: `提现`,
            wayDesc: "是否提现" + this.tixiancoin + "？",
            confirmText: "是",
            cancelText: "否",
            confirm: () => {
                NetAdapter.tixian(param).then((res) => {
                    console.log("提现", res);
                    AlertManager.showNormalTips(res.msg);
                    Notifier.send(ListenID.Revenue_getUserProfit);
                    this.onClose()
                })
            },
        });
    }

    // update (dt) {}
}
